<html>
<!-- =====================================================================

  File:      usp_ProductsBySubCategory.htm for Adventure Works Cycles Storefront Sample
  Summary:   Self-documentation for application
  Date:	     June 16, 2003

=====================================================================

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= -->
    <head>
        <title>Adventure Works Cycles Store Documentation</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <h1>"usp_ProductsBySubCategory" Stored Procedure</h1>

        <b>Description:</b>

        <P>This stored procedure accepts a SubCategoryID and returns all the products in the
        Product table in that category. This list is used to populate the _menu user control,
        and is the engine behind the product list page.</P>

        <b>Definition:</b>

<pre style="background-color:white">
<span style="color: #0000FF"><strong>CREATE</strong></span> Procedure usp_ProductsBySubcategory
<span style="color: #4444FF">(</span>
    @SubcategoryID <span style="color: #2040a0"><strong>int</strong></span><span style="color: #4444FF">,</span>
	@Culture <span style="color: #2040a0"><strong>nvarchar</strong></span><span style="color: #4444FF">(</span>10<span style="color: #4444FF">)</span> 
<span style="color: #4444FF">)</span>
<span style="color: #0000FF"><strong>AS</strong></span>

<span style="color: #0000FF"><strong>SELECT</strong></span> 
    P.ProductID<span style="color: #4444FF">,</span>
    P.[<span style="color: #0000FF"><strong>Name</strong></span>]<span style="color: #4444FF">,</span>
    dbo.ConvertCurrency<span style="color: #4444FF">(</span>P.ListPrice<span style="color: #4444FF">,</span> @Culture<span style="color: #4444FF">)</span>.ToString<span style="color: #4444FF">(</span><span style="color: #4444FF">)</span> <span style="color: #0000FF"><strong>as</strong></span> ListPrice<span style="color: #4444FF">,</span>
    PP.ThumbnailPhotoFileName<span style="color: #4444FF">,</span>
    PSC.ProductCategoryID

<span style="color: #0000FF"><strong>FROM</strong></span> 
      Production.Product <span style="color: #0000FF"><strong>AS</strong></span> P 
LEFT OUTER JOIN Production.ProductSubcategory <span style="color: #0000FF"><strong>AS</strong></span> PSC <span style="color: #0000FF"><strong>on</strong></span> P.ProductSubcategoryID <span style="color: #4444FF">=</span> PSC.ProductSubcategoryID
LEFT OUTER JOIN Production.ProductProductPhoto <span style="color: #0000FF"><strong>AS</strong></span> PPP <span style="color: #0000FF"><strong>on</strong></span> P.ProductID<span style="color: #4444FF">=</span>PPP.ProductID
LEFT OUTER JOIN Production.ProductPhoto <span style="color: #0000FF"><strong>AS</strong></span> PP <span style="color: #0000FF"><strong>ON</strong></span> PP.ProductPhotoID<span style="color: #4444FF">=</span>PPP.ProductPhotoID

<span style="color: #0000FF"><strong>WHERE</strong></span> 
    P.ProductSubcategoryID <span style="color: #4444FF">=</span> @SubcategoryID 
	<span style="color: #0000FF"><strong>AND</strong></span> P.ListPrice <span style="color: #0000FF"><strong>IS</strong></span> <span style="color: #0000FF"><strong>NOT</strong></span> <span style="color: #0000FF"><strong>NULL</strong></span>  
	<span style="color: #0000FF"><strong>AND</strong></span> P.FinishedGoodsFlag <span style="color: #4444FF">=</span> 1
	<span style="color: #0000FF"><strong>AND</strong></span> <span style="color: #4444FF">(</span>PPP.ProductID <span style="color: #0000FF"><strong>IS</strong></span> <span style="color: #0000FF"><strong>NULL</strong></span> <span style="color: #0000FF"><strong>OR</strong></span> PPP.[<span style="color: #0000FF"><strong>Primary</strong></span>] <span style="color: #4444FF">=</span> 1 <span style="color: #4444FF">)</span>


<span style="color: #0000FF"><strong>ORDER BY</strong></span> 
    P.[<span style="color: #0000FF"><strong>Name</strong></span>]<span style="color: #4444FF">,</span> 
    P.ProductID<span style="color: #4444FF">,</span>
	PPP.ModifiedDate;


</pre>

        <b>Database Tables Used: </b>

        <P><i>Product</i>, <i>ProductSubCategory</i>, <i>ProductPhoto</i>:
        <br>The Product table contains the core information about all of the items for sale
        on the Adventure Works Cycles web site. Its primary key is the ProductID identity field. 
        <br>The ProductSubCategory table contains a list of all subgroups of products stored in the database.
        <br>The ProductPhoto table contains information about the pictures of the products.

        <p>

        <img src="1x1.gif" width=25> <IMG src="../docs/images/Product-Subcategory-Photo.gif" width="900" height="705">


    </body>
</html>
